<?php
/**
 * Created by PhpStorm.
 * User: hoter.zhang
 * Date: 2016/12/7
 * Time: 14:56
 */

namespace app\core\lib;



use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;

class ActionColumn extends \yii\grid\ActionColumn
{

    public $buttonOptions = [
        //"class"=>"btn btn-default btn-xs"
    ];
    public $template = '{view} {update} {delete}';


    /**
     * Initializes the default button rendering callbacks.
     */
    protected function initDefaultButtons()
    {

        //parent::initDefaultButtons();

        if (!isset($this->buttons['view'])) {
            $this->buttons['view'] = function ($url, $model, $key) {
                $options = array_merge([
                    'class' => 'btn btn-success btn-xs',
                    'title' => Yii::t('yii', 'View'),
                    'aria-label' => Yii::t('yii', 'View'),
                    'data-pjax' => '0',
                ], $this->buttonOptions);
                return Html::a('<span class="glyphicon glyphicon-eye-open"></span> '. Yii::t('yii', 'View'), $url, $options);
            };
        }
        if (!isset($this->buttons['update'])) {
            $this->buttons['update'] = function ($url, $model, $key) {
                $options = array_merge([
                    'class' => 'btn btn-primary btn-xs',
                    'title' => Yii::t('yii', 'Update'),
                    'aria-label' => Yii::t('yii', 'Update'),
                    'data-pjax' => '0',
                ], $this->buttonOptions);
                return Html::a('<span class="glyphicon glyphicon-pencil"></span>' . '修改', $url, $options);
            };
        }
        if (!isset($this->buttons['delete'])) {
            $this->buttons['delete'] = function ($url, $model, $key) {
                $options = array_merge([
                    'class' => 'btn btn-danger btn-xs delete',
                    'title' => Yii::t('yii', 'Delete'),
                    'aria-label' => Yii::t('yii', 'Delete'),
//                    'data-confirm' => Yii::t('yii', 'Are you sure you want to delete this item?'),
//                    'data-method' => 'post',
                    'deleteId' => $key,

                ], $this->buttonOptions);
                return Html::a('<span class="glyphicon glyphicon-trash"></span> '. Yii::t('yii', 'Delete'), 'javascript:;', $options);
            };
        }

        if (!isset($this->buttons['create'])) {
            $this->buttons['create'] = function ($url) {
                $options = ArrayHelper::merge([
                    'title' => Yii::t('backend', 'Create'),
                    'aria-label' => Yii::t('backend', 'Create'),
                    'data-pjax' => '0',
                ], $this->buttonOptions);

                return Html::a('<span class="glyphicon glyphicon-plus"></span> '.  Yii::t('yii', 'Create'), $url, $options);
            };
        }
        if (!isset($this->buttons['up'])) {
            $this->buttons['up'] = function ($url) {
                $options = ArrayHelper::merge([
                    'title' => Yii::t('backend', 'Up'),
                    'aria-label' => Yii::t('backend', 'Up'),
                    'data-pjax' => '0',
                ], $this->buttonOptions);

                return Html::a('<span class="glyphicon glyphicon-arrow-up"></span>', $url, $options);
            };
        }
        if (!isset($this->buttons['down'])) {
            $this->buttons['down'] = function ($url) {
                $options = ArrayHelper::merge([
                    'title' => Yii::t('backend', 'Down'),
                    'aria-label' => Yii::t('backend', 'Down'),
                    'data-pjax' => '0'
                ], $this->buttonOptions);

                return Html::a('<span class="glyphicon glyphicon-arrow-down"></span>', $url, $options);
            };
        }

    }
}